package cn.wolfcode.luowowo.article.service.impl;

import cn.wolfcode.luowowo.article.domain.TravelCommend;
import cn.wolfcode.luowowo.article.mapper.TravelCommendMapper;
import cn.wolfcode.luowowo.article.query.TravelCommendQuery;
import cn.wolfcode.luowowo.article.service.ITravelCommendService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;


@Service
public class TravelCommendServiceImpl implements ITravelCommendService {

    @Autowired
    private TravelCommendMapper travelCommendMapper;

    @Override
    public PageInfo<TravelCommend> query(TravelCommendQuery qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        return new PageInfo<>(travelCommendMapper.selectForList(qo));
    }

    @Override
    public void saveOrUpdate(TravelCommend strategy) {
        if (strategy.getId() == null) {
            travelCommendMapper.insert(strategy);
        } else {
            travelCommendMapper.updateByPrimaryKey(strategy);
        }
    }

    @Override
    public List<TravelCommend> list() {
        return travelCommendMapper.selectAll();
    }

    @Override
    public TravelCommend get(Long sid) {
        return travelCommendMapper.selectByPrimaryKey(sid);
    }

    @Override
    public List<TravelCommend> selectHotTop5() {
        return travelCommendMapper.selectHotTop5();
    }
}
